import pipeline.MysqlTestPipeline;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Selectable;

import java.sql.SQLException;
import java.util.*;

public class CrawlerJsonTest implements PageProcessor {

    private Site site = Site.me().setRetryTimes(3).setSleepTime(100);

    @Override
    public void process(Page page) {
        System.out.println("输出：");
        String taskId = UUID.randomUUID().toString();
        String name = page.getHtml().toString();
        System.out.println(page.getJson().jsonPath("advertisingqualityhotels").toString());

    }

    @Override
    public Site getSite() {
        return site;
    }

    public static void main(String[] args) {
//        try {
            Spider.create(new CrawlerJsonTest())
                    .addUrl("https://hotels.ctrip.com/Domestic/tool/AjaxGetCPTList.ashx?advpositioncode=HTL_LST_001,HTL_LST_002,HTL_LST_004&city=1&checkin=2020-01-15&checkout=2020-01-16&star=")
//                    .addPipeline(new MysqlTestPipeline())
                    .thread(1)
                    .run();
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
        /*Pattern pattern = Pattern.compile("\\】(.*?)\\。");
        Matcher matcher = pattern.matcher("】上海交通大学。");
        while (matcher.find()){
            System.out.println(matcher.group(1));
        }*/
    }

}
